import 'package:flutter/material.dart';
import 'package:short_video_app/entity/home/comment_list_entity.dart';
import 'package:short_video_app/entity/home/video_list_entity.dart';
import 'package:short_video_app/ui/widgets/custom_refresh_mixin.dart';
import 'package:short_video_app/network/base_entity.dart';
import 'package:short_video_app/network/http_manager.dart';
import 'package:short_video_app/utils/hud_util.dart';

class CommentVideoViewModel extends ChangeNotifier with CustomRefreshMixin {
  final VideoEntity? videoEntity;

  CommentVideoViewModel({this.videoEntity});

  @override
  Future<List> requestList(int page) async {
    List tempL = [];
    Map<String, dynamic> params = {};
    params['id'] = videoEntity?.id ?? '0';
    params["size"] = 5;
    params["current"] = page;

    IBaseEntity? result = await HttpManager.getInstance().request(url: "/api/app/video/videoComment", params: params);

    if (result?.isSuccess() == true) {
      CommentListEntity listResult = CommentListEntity.fromJson(result?.getData());
      List<CommentEntity>? temps = listResult.list;
      if (temps != null) {
        tempL.addAll(temps);
      }
      hasNext = listResult.hasNext ?? false;
    } else {
      HudUtil.toast(result?.getMsg() ?? "");
    }

    return tempL;
  }

  @override
  void onRequestComplete() {
    notifyListeners();
  }
}
